<template>
  <div class="comSelect-container">
    <JsbosTreeSelect
      :options="treeData"
      v-model="innerValue"
      v-on="$listeners"
      v-bind="$attrs"
      :lastLevel="lastLevel"
      lastLevelKey="type"
      lastLevelValue="department"
    >
    </JsbosTreeSelect>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "companySelect",
  props: {
    value: {
      default: "",
    },
    lastLevel: {
      type: Boolean,
      default: true,
    },
    source: {
      type: String,
      default: "",
    },
  },
  model: {
    prop: "value",
    event: "input",
  },
  data() {
    return {
      treeData: [],
      innerValue: this.value,
    };
  },
  methods: {
    getData() {
      request({
        url: "/api/permission/Organize",
        method: "get",
      }).then((res) => {
        this.treeData = res.data.list;
      });
    },
    // async getData() {
    //   this.treeData = await this.$store.dispatch('generator/getDepTree')
    //   if (this.source && this.source == "contract") {
    //     var organizeId = this.$store.getters.userInfo.organizeId;
    //     this.treeData.forEach((element) => {
    //       element.children.forEach((ee) => {
    //         if (ee.id != organizeId) {
    //           element.children = element.children.filter(
    //             (item) => !Object.is(item, ee)
    //           );
    //         }
    //       });
    //     });
    //   }
    //   this.recursionData(this.treeData)
    //   console.log(this.treeData,'----')
    // },
    // recursionData(arr) {
    //     arr.forEach((item, index) => {
    //         if(item.type != 'company') {
    //             console.log(item,index,'--------')
    //             arr.splice(index ,1)
    //         }else {
    //             if(item.children && item.children.length>0) {
    //                 this.recursionData(item.children)
    //             }
    //         }

    //     })
    // }
  },
  created() {
    this.getData();
  },
  watch: {
    innerValue(val) {
      // val && this.$emit('change', val)
    },
    value(val) {
      this.innerValue = val;
    },
  },
};
</script>
<style lang="scss">
.comSelect-container {
  .el-select {
    width: 100%;
  }
}
</style>
